﻿namespace AnyOffice.WebControls
{
    using System;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    [ToolboxData("<{0}:HFRadioButton runat=server></{0}:HFRadioButton>"), DefaultProperty("Text")]
    public class HFRadioButton : RadioButton
    {
        private bool blChecked;
        private string strChineseName = "";
        private string strPropertyName = "";
        private string strPropertyValue = "";
        private string strSelectValue = "0";

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.CssClass = "dibg";
        }

        public override bool Checked
        {
            get
            {
                if (this.blChecked)
                {
                    this.SelectValue = "1";
                }
                else
                {
                    this.SelectValue = "0";
                }
                return this.blChecked;
            }
            set
            {
                this.blChecked = value;
            }
        }

        [Bindable(true), Category("HFServer"), Browsable(true), Description("属性对应的中文名，目的是在数据校验的时候抛出异常提示时使用")]
        public string ChineseName
        {
            get
            {
                if (base.Attributes["ChineseName"] != null)
                {
                    this.strChineseName = base.Attributes["ChineseName"].Trim();
                }
                return this.strChineseName;
            }
            set
            {
                this.strChineseName = value;
                base.Attributes.Add("ChineseName", this.strChineseName);
            }
        }

        [Browsable(true), Category("HFServer"), Description("对应实体类属性的名称"), Bindable(true)]
        public string PropertyName
        {
            get
            {
                if (base.Attributes["PropertyName"] != null)
                {
                    this.strPropertyName = base.Attributes["PropertyName"].Trim();
                }
                return this.strPropertyName;
            }
            set
            {
                this.strPropertyName = value;
                base.Attributes.Add("PropertyName", this.strPropertyName);
            }
        }

        [Bindable(true), Description("保存控件对应数据库字段当前行的原值"), Category("HFServer"), Browsable(true)]
        public string PropertyValue
        {
            get
            {
                if (base.Attributes["PropertyValue"] != null)
                {
                    this.strPropertyValue = base.Attributes["PropertyValue"];
                }
                return this.strPropertyValue;
            }
            set
            {
                this.strPropertyValue = value;
                base.Attributes.Add("PropertyValue", this.strPropertyValue);
            }
        }

        [Bindable(true), Category("HFServer"), Browsable(true), Description("True和False对应的数据库字段值,True表示1，false表示0"), ReadOnly(true)]
        public string SelectValue
        {
            get
            {
                if (base.Attributes["SelectValue"] != null)
                {
                    this.strSelectValue = base.Attributes["SelectValue"].Trim();
                }
                return this.strSelectValue;
            }
            set
            {
                this.strSelectValue = value;
                base.Attributes.Add("SelectValue", this.strSelectValue);
            }
        }
    }
}

